package me.send.data.service.provider;

import java.util.Map;
import me.send.business.base.SendVariable;
import me.send.data.service.pojo.Broker;

public class BrokerProvider {
	/**
	 * 所有城市
	 */
	private static final String ALL_CITY_STR="allCity";
	// brokerid,username,nickname,password,createtime,updatetime,status,telephone,sex,headerpath
	// 提供批量删除功能 2015年7月6日17:03:01
	public String batch_delete(Map<String, Object> parameter) {
		String brokerids = (String) parameter.get("brokerids");
		String sql = "";
		if (brokerids != null && !brokerids.equals("")) {
			// sql = "delete from popuser where popid in (" + brokerids
			// + ")";
			sql = "UPDATE popuser SET isdelete = 1 where popid in ("
					+ brokerids + ")";
		}
		return sql;
	}

	public String list_page(Map<String, Object> parameter) {
		// 获取 对象 查询对象 2015年6月23日17:34:01
		Broker broker = (Broker) parameter.get(SendVariable.DATA);
		String cityName = (String)parameter.get("cityName");
		// 判断下面的字段 是否是null
		String sql = "select * from popuser where isdelete=0 ";
		if (broker != null) {
			if (broker.getUsername() != null
					&& !broker.getUsername().equals("")) {
				sql += " and username like '%" + broker.getUsername() + "%'";
			}
			if (broker.getTelephone() != null
					&& !broker.getTelephone().equals("")) {
				sql += " and telephone like '%" + broker.getTelephone() + "%'";
			}
			if (broker.getLevel() > 0) {
				sql += " and level = " + broker.getLevel() + " ";
			}
			if (broker.getSex() > -1) {
				sql += " and sex = " + broker.getSex() + "";
			}
		}
		if (cityName!=null &&!"".equals(cityName)) {
			if (!ALL_CITY_STR.equals(cityName)) {
				sql +=" AND cityname = '"+cityName+"'";
			}
		}
		sql += " limit #{PAGE.start},#{PAGE.rows} ";
		return sql;
	}
	
	public String unAuthenedList(Map<String, Object> parameter) {
		// 获取 对象 查询对象 2015年6月23日17:34:01
		
		Broker broker = (Broker) parameter.get(SendVariable.DATA);
		String cityName = (String)parameter.get("cityName");
		// 判断下面的字段 是否是null
		String sql = "select * from popuser p where p.isdelete=0 AND p.isauthen=1";
		if (broker != null) {
			if (broker.getUsername() != null
					&& !broker.getUsername().equals("")) {
				sql += " and username like '%" + broker.getUsername() + "%'";
			}
			if (broker.getLevel() > 0) {
				sql += " and level = " + broker.getLevel() + " ";
			}
			if (broker.getSex() > 0) {
				sql += " and sex = " + broker.getSex() + "";
			}
		}
		if (cityName!=null &&!"".equals(cityName)) {
			if (!ALL_CITY_STR.equals(cityName)) {
				sql +=" AND cityname = '"+cityName+"'";
			}
		}
		sql += " limit #{PAGE.start},#{PAGE.rows} ";
		return sql;
	}

	public String count(Map<String, Object> parameter) {
		// 获取 对象 查询对象 2015年6月23日17:34:01
		Broker broker = (Broker) parameter.get(SendVariable.DATA);
		// 判断下面的字段 是否是null
		String sql = "select count(1) as total from popuser where isdelete=0 ";
		if (broker != null) {
			if (broker.getUsername() != null
					&& !broker.getUsername().equals("")) {
				sql += " and username like '%" + broker.getUsername() + "%'";
			}
			if (broker.getTelephone() != null
					&& !broker.getTelephone().equals("")) {
				sql += " and telephone like '%" + broker.getTelephone() + "%'";
			}
			if (broker.getLevel() > 0) {
				sql += " and level = " + broker.getLevel() + " ";
			}
			if (broker.getSex() > 0) {
				sql += " and sex = " + broker.getSex() + "";
			}
		}
		return sql;
	}
	
	public String countUnauthed(Map<String, Object> parameter) {
		// 获取 对象 查询对象 2015年6月23日17:34:01
		Broker broker = (Broker) parameter.get(SendVariable.DATA);
		// 判断下面的字段 是否是null
		String sql = "select count(1) as total from popuser where isdelete=0 AND isauthen=1";
		if (broker != null) {
			if (broker.getUsername() != null
					&& !broker.getUsername().equals("")) {
				sql += " and username like '%" + broker.getUsername() + "%'";
			}
			if (broker.getLevel() > 0) {
				sql += " and level = " + broker.getLevel() + " ";
			}
			if (broker.getSex() > 0) {
				sql += " and sex = " + broker.getSex() + "";
			}
		}
		return sql;
	}
}
